package com.kinon.tyjaccount.view;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.kinon.tyjaccount.R;
import com.kinon.tyjaccount.tools.HttpTools;
import com.kinon.tyjaccount.tools.NetWorkUtil;
import com.kinon.tyjaccount.tools.ToastUtil;
import com.loopj.android.http.JsonHttpResponseHandler;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

public class GongzuorenyuanActivity extends Activity {

	private TextView tv_fanhui;
	private TextView tv_username;
	private TextView tv_name;
	private TextView tv_phone;
	String token;
	
	HttpTools httptools=null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gongzuorenyuan);
		initRes();
	}

	private void initRes() {
		SharedPreferences sp = getSharedPreferences("spReg",
				Context.MODE_PRIVATE);
		token = sp.getString("data", "");
		tv_username=(TextView)findViewById(R.id.tv_username) ;
		tv_name=(TextView)findViewById(R.id.tv_name);
		tv_phone=(TextView)findViewById(R.id.tv_phone);
		tv_fanhui=(TextView)findViewById(R.id.tv_fanhui);
		tv_fanhui.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		Info();
	}

	
	private void Info() {
		if(NetWorkUtil.isNetwork(getApplicationContext())==false)
		{
			ToastUtil toastUtil=new ToastUtil();
			toastUtil.Short(getApplicationContext(),"  "+"当前网络不可用")
					.setToastBackground(Color.WHITE,0).show();
			return;
		}
		if (httptools == null) {
			httptools = new HttpTools(GongzuorenyuanActivity.this);
		}
		httptools.info(token,new JsonInfo());
	}
	public class JsonInfo extends JsonHttpResponseHandler {
		@Override
		public void onSuccess(int statusCode, Header[] headers,
				JSONObject response) {
			// TODO Auto-generated method stub
			super.onSuccess(statusCode, headers, response);
			Log.i("info", "info---"+response.toString());
			try {
				boolean code = response.getBoolean("code");
				String msg = response.getString("msg");
				if(code==true){
					JSONObject object = response.getJSONObject("data");
					String username = object.getString("username");
					String name = object.getString("name");
					String cellphone = object.getString("cellphone");
//					et_pay.setText("");
//					handler.removeCallbacks(runnable);
//					Toast.makeText(JiesuanjineActivity.this, msg, Toast.LENGTH_SHORT).show();
//					finish();
					tv_username.setText(username);
					tv_name.setText(name);
					tv_phone.setText(cellphone);
				}else{
//					handler.postDelayed(runnable, 1000);
//					et_pay.setText("");
					Toast.makeText(GongzuorenyuanActivity.this, msg, Toast.LENGTH_SHORT).show();
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
			
		}
		@Override
		public void onFailure(Throwable e, JSONObject errorResponse) {
			super.onFailure(e, errorResponse);
			Toast.makeText(GongzuorenyuanActivity.this,
					"网络请求失败", Toast.LENGTH_SHORT).show();
		}
	}
	
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
	       super.onWindowFocusChanged(hasFocus);
	       if (hasFocus) {
	            View decorView = getWindow().getDecorView();
	                 decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
	                  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
	                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
	                  |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
	                  |View.SYSTEM_UI_FLAG_FULLSCREEN);
	               }
	}
}
